package jp.bsws.bl;

import java.math.BigDecimal;
import java.sql.Connection;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.List;

import jp.bsws.bean.GekkeiJohoBean;
import jp.bsws.bean.KeyValueBean;
import jp.bsws.bean.KeyValueSyukeiBean;
import jp.bsws.bean.MasterBean;
import jp.bsws.bean.NenkanJohoBean;
import jp.bsws.bean.NikkeiJohoBean;
import jp.bsws.bean.RaitenJohoBean;
import jp.bsws.common.BSWSConstants;
import jp.bsws.common.BSWSSession;
import jp.bsws.common.BSWSUtils;
import jp.bsws.common.DBUtils;
import jp.bsws.dao.BSWSDao;
import jp.bsws.dao.JugyoinDao;
import jp.bsws.dao.JugyoinRelationDao;
import jp.bsws.dao.KengenDao;
import jp.bsws.dao.TenpoDao;
import jp.bsws.dao.UriageDao;
import jp.bsws.model.GroupModel;
import jp.bsws.model.JugyoinModel;
import jp.bsws.model.JugyoinRelationModel;
import jp.bsws.model.KengenModel;
import jp.bsws.model.TenpoModel;
import jp.bsws.model.UriageModel;
import jp.bsws.model.UriageSyosaiModel;

public class BSWSBl {

	/**
	 * ログイン情報を取得
	 * @param strMailAddress
	 * @param strPasswd
	 * @param strSansyoYmd
	 * @return
	 * @throws Exception
	 */
	public BSWSSession getLoginJoho(String strMailAddress, String strPasswd, String strSansyoYmd) throws Exception{
		BSWSSession bSWSSession = new BSWSSession();
		BSWSDao bSWSDao = BSWSDao.getInstance();
		TenpoDao tenpoDao = TenpoDao.getInstance();
		KengenDao kengenDao = KengenDao.getInstance();

		Connection con = DBUtils.getConnection();

		try{
			//ユーザー情報取得
			JugyoinModel jugyoinModel =  bSWSDao.getLoginJoho(con, strMailAddress, strPasswd, strSansyoYmd);
			if(jugyoinModel == null){
				bSWSSession.setStrErrorMsg(BSWSConstants.MSG_NO_JUGYOIN);
				return bSWSSession;
			}

			//グループ情報
			List<GroupModel> groupModelList  = bSWSDao.getGroupJoho(con, jugyoinModel.getStrGroupCod());
			if(BSWSUtils.isZeroNull(groupModelList)){
				bSWSSession.setStrErrorMsg(BSWSConstants.MSG_NO_GROUP);
				return bSWSSession;
			}
			GroupModel groupModel = groupModelList.get(0);

			//店舗情報
			List<TenpoModel> tenpoModelList  =
				bSWSDao.getTenpoJoho(con, null, jugyoinModel.getStrGroupCod(), jugyoinModel.getStrTenpoCod(), strSansyoYmd);
			if(BSWSUtils.isZeroNull(tenpoModelList)){
				bSWSSession.setStrErrorMsg(BSWSConstants.MSG_NO_TENPO);
				return bSWSSession;
			}
			TenpoModel tenpoModel = tenpoModelList.get(0);
			//権限情報
			List<KengenModel> kengenModelList  = kengenDao.getKengenJoho(con,  jugyoinModel.getIntKengenSeq(), jugyoinModel.getStrGroupCod(), null, null);
			if(BSWSUtils.isZeroNull(kengenModelList)){
				bSWSSession.setStrErrorMsg(BSWSConstants.MSG_NO_KENGEN);
				return bSWSSession;
			}
			KengenModel kengenModel = kengenModelList.get(0);
			//参照可能店舗リスト
			List<KeyValueBean> sansyoTenpoList
				= tenpoDao.getTenpoList(con, jugyoinModel.getStrGroupCod(), jugyoinModel.getStrTenpoCod(),  kengenModel.getStrTenpoSansyoKbn() );

			bSWSSession.setStrGroupCod(jugyoinModel.getStrGroupCod());
			bSWSSession.setStrGroupKnj(groupModel.getStrGroupKnj());
			bSWSSession.setStrTenpoCod(jugyoinModel.getStrTenpoCod());
			bSWSSession.setStrTenpoKnj(tenpoModel.getStrTenpoKnj());
			bSWSSession.setIntJugyoinSeq(jugyoinModel.getSeq());
			bSWSSession.setStrJugyoinCod(jugyoinModel.getStrJugyoinCod());
			bSWSSession.setStrJugyoinKnj(jugyoinModel.getStrJugyoinKnj());
			bSWSSession.setIntKengenSeq(kengenModel.getSeq());
			bSWSSession.setStrKengenKnj(kengenModel.getStrKengenKnj());
			bSWSSession.setStrTenpoSansyoKbn(kengenModel.getStrTenpoSansyoKbn());
			bSWSSession.setStrJugyoinSansyoKbn(kengenModel.getStrJugyoinSansyoKbn());
			bSWSSession.setStrSetteiHenkoKbn(kengenModel.getStrSetteiHenkoKbn());
			bSWSSession.setStrSansyoTenpoCod(jugyoinModel.getStrTenpoCod());
			bSWSSession.setSansyoTenpoList(sansyoTenpoList);
		}finally{
			con.close();
		}

		return bSWSSession;
	}


	public List<RaitenJohoBean> getRaitenJoho(
			Connection con, BSWSSession bSWSSession,
			List<MasterBean> raitenYoinHList,
			List<MasterBean> uriageShubetsuHList,
			List<MasterBean> shiharaiHohoHList,
			List<MasterBean> hosyuShubetsuHList,
			String strSansyoTenpoCod, String strSansyoYmd) throws Exception{

		UriageDao uriageDao = UriageDao.getInstance();
		JugyoinDao jugyoinDao = JugyoinDao.getInstance();

		// 売上情報取得
		List<UriageModel> uriageModelList = uriageDao.getUriageJoho(con,
				bSWSSession.getStrGroupCod(), strSansyoTenpoCod, Integer.parseInt(strSansyoYmd));

		// 売上来店要因情報取得
		List<UriageSyosaiModel> uriageRaitenYoinList = uriageDao.getUriageSyosaiJoho(con,
				bSWSSession.getStrGroupCod(), strSansyoTenpoCod, Integer.parseInt(strSansyoYmd), null, BSWSConstants.KBN_RAITEN_YOIN, null);
		// 売上売上種別情報取得
		List<UriageSyosaiModel> uriageUriageShubetsuList = uriageDao.getUriageSyosaiJoho(con,
				bSWSSession.getStrGroupCod(), strSansyoTenpoCod, Integer.parseInt(strSansyoYmd), null, BSWSConstants.KBN_URIAGE_SHUBETSU, null);
		// 売上支払方法情報取得
		List<UriageSyosaiModel> uriageShiharaiHohoList = uriageDao.getUriageSyosaiJoho(con,
				bSWSSession.getStrGroupCod(), strSansyoTenpoCod, Integer.parseInt(strSansyoYmd), null, BSWSConstants.KBN_SHIHARAI_HOHO, null);
		// 売上報酬種別情報取得
		List<UriageSyosaiModel> uriageHosyuShubetsuList = uriageDao.getUriageSyosaiJoho(con,
				bSWSSession.getStrGroupCod(), strSansyoTenpoCod, Integer.parseInt(strSansyoYmd), null, BSWSConstants.KBN_HOSYU_SHUBETSU, null);

		//従業員報酬種別情報を取得
		JugyoinRelationDao jugyoinRelationDao = JugyoinRelationDao.getInstance();
		List<JugyoinRelationModel> jugyoinRelationModeList
			= jugyoinRelationDao.getJugyoinRelationInfo(con, bSWSSession.getStrGroupCod(), null, BSWSConstants.KBN_HOSYU_SHUBETSU_WARIAI, null);

		//従業員リスト
		List<KeyValueBean> kvJugyoinList = new ArrayList<KeyValueBean>();
		if(BSWSConstants.C_JUGYOIN_SANSYO_ALL.equals(bSWSSession.getStrJugyoinSansyoKbn())){
			kvJugyoinList =  jugyoinDao.getJugyoinList(con, bSWSSession.getStrGroupCod(), strSansyoTenpoCod );
		}else{
			kvJugyoinList.add(new KeyValueBean(String.valueOf(bSWSSession.getIntJugyoinSeq()),bSWSSession.getStrJugyoinKnj()));
		}

		List<RaitenJohoBean> raitenJohoBeanList = new ArrayList<RaitenJohoBean>();
		for(UriageModel uriageModel : uriageModelList){
			RaitenJohoBean raitenJohoBean = new RaitenJohoBean();
			raitenJohoBean.setJugyoinList(kvJugyoinList);
			raitenJohoBean.setIntTantoSeq(uriageModel.getIntJugyoinSeq());
			raitenJohoBean.setStrTantoKnj(uriageModel.getStrJugyoinKnj());
			raitenJohoBean.setIntShinki(uriageModel.getIntShinkiSu());
			raitenJohoBean.setIntSairai(uriageModel.getIntSairaiSu());
			raitenJohoBean.setIntShimei(uriageModel.getIntShimeiSu());
			raitenJohoBean.setIntNyukyaku(uriageModel.getIntNyukyakuSu());
			raitenJohoBean.setIntHontaiKingaku(uriageModel.getIntHontaiKin());
			raitenJohoBean.setIntSyohizei(uriageModel.getIntSyohizeiKin());
			raitenJohoBean.setIntUriageGokei(uriageModel.getIntUriageGokeiKin());
			raitenJohoBean.setIntTanka(uriageModel.getIntTankaKin());
			raitenJohoBean.setIntHosyuGokei(uriageModel.getIntHosyuGokeiKin());

			List<MasterBean> raitenYoinList = new ArrayList<MasterBean>();
			//ヘッダー順にリスト作成
			for(MasterBean masterBean:raitenYoinHList){
				MasterBean mb = new MasterBean();
				mb.setIntSeq(masterBean.getIntSeq());
				mb.setIntValue(0);
				//数字のリスト化
				for(UriageSyosaiModel uriageSyosaiModel:uriageRaitenYoinList){
					//一致するものだけADD
					if(uriageModel.getStrGroupCod().equals(uriageSyosaiModel.getStrGroupCod())
							&& uriageModel.getStrTenpoCod().equals(uriageSyosaiModel.getStrTenpoCod())
							&& uriageModel.getIntJugyoinSeq() == uriageSyosaiModel.getIntJugyoinSeq() //ここまで１行の単位
							&& masterBean.getIntSeq() == uriageSyosaiModel.getIntSeq() //列の単位
							){
						mb.setIntValue(uriageSyosaiModel.getIntAtai());
					}
				}
				raitenYoinList.add(mb);
			}
			raitenJohoBean.setRaitenYoinList(raitenYoinList);

			List<MasterBean> uriageShubetsuList = new ArrayList<MasterBean>();
			//ヘッダー順にリスト作成
			for(MasterBean masterBean:uriageShubetsuHList){
				MasterBean mb = new MasterBean();
				mb.setIntSeq(masterBean.getIntSeq());
				mb.setIntValue(0);
				//数字のリスト化
				for(UriageSyosaiModel uriageSyosaiModel:uriageUriageShubetsuList){
					//一致するものだけADD
					if(uriageModel.getStrGroupCod().equals(uriageSyosaiModel.getStrGroupCod())
							&& uriageModel.getStrTenpoCod().equals(uriageSyosaiModel.getStrTenpoCod())
							&& uriageModel.getIntJugyoinSeq() == uriageSyosaiModel.getIntJugyoinSeq() //ここまで１行の単位
							&& masterBean.getIntSeq() == uriageSyosaiModel.getIntSeq() //列の単位
							){
						mb.setIntValue(uriageSyosaiModel.getIntAtai());
					}
				}
				uriageShubetsuList.add(mb);
			}
			raitenJohoBean.setUriageShubetsuList(uriageShubetsuList);

			List<MasterBean> shiharaiHohoList = new ArrayList<MasterBean>();
			//ヘッダー順にリスト作成
			for(MasterBean masterBean:shiharaiHohoHList){
				MasterBean mb = new MasterBean();
				mb.setIntSeq(masterBean.getIntSeq());
				mb.setHontaiKeijoFlg(masterBean.getHontaiKeijoFlg());
				mb.setIntValue(0);
				//数字のリスト化
				for(UriageSyosaiModel uriageSyosaiModel:uriageShiharaiHohoList){
					//一致するものだけADD
					if(uriageModel.getStrGroupCod().equals(uriageSyosaiModel.getStrGroupCod())
							&& uriageModel.getStrTenpoCod().equals(uriageSyosaiModel.getStrTenpoCod())
							&& uriageModel.getIntJugyoinSeq() == uriageSyosaiModel.getIntJugyoinSeq() //ここまで１行の単位
							&& masterBean.getIntSeq() == uriageSyosaiModel.getIntSeq() //列の単位
							){
						mb.setIntValue(uriageSyosaiModel.getIntAtai());
					}
				}
				shiharaiHohoList.add(mb);
			}
			raitenJohoBean.setShiharaiHohoList(shiharaiHohoList);

			List<MasterBean> hosyuShubetsuList = new ArrayList<MasterBean>();
			//ヘッダー順にリスト作成
			for(MasterBean masterBean:hosyuShubetsuHList){
				MasterBean mb = new MasterBean();
				mb.setIntSeq(masterBean.getIntSeq());
				mb.setStrKeisanMotoCod(masterBean.getStrKeisanMotoCod());
				mb.setBdWariai(masterBean.getBdWariai());
				mb.setIntValue(0);
				for(JugyoinRelationModel jugyoinRelationModel:jugyoinRelationModeList){
					if(uriageModel.getStrGroupCod().equals(jugyoinRelationModel.getStrGroupCod())
							&& uriageModel.getIntJugyoinSeq() == jugyoinRelationModel.getIntJugyoinSeq() //ここまで１行の単位
							&& masterBean.getIntSeq().equals(jugyoinRelationModel.getIntSeq()) //列の単位
							&& BSWSUtils.isNotBlankNull(jugyoinRelationModel.getStrAtai())
							){
						mb.setBdWariai(BigDecimal.valueOf(Long.parseLong(jugyoinRelationModel.getStrAtai())));
					}
				}
				//数字のリスト化
				for(UriageSyosaiModel uriageSyosaiModel:uriageHosyuShubetsuList){
					//一致するものだけADD
					if(uriageModel.getStrGroupCod().equals(uriageSyosaiModel.getStrGroupCod())
							&& uriageModel.getStrTenpoCod().equals(uriageSyosaiModel.getStrTenpoCod())
							&& uriageModel.getIntJugyoinSeq() == uriageSyosaiModel.getIntJugyoinSeq() //ここまで１行の単位
							&& masterBean.getIntSeq() == uriageSyosaiModel.getIntSeq() //列の単位
							){
						mb.setIntValue(uriageSyosaiModel.getIntAtai());
					}
				}

				hosyuShubetsuList.add(mb);
			}
			raitenJohoBean.setHosyuShubetsuList(hosyuShubetsuList);

			raitenJohoBeanList.add(raitenJohoBean);
		}


		//件数分補足
		//店舗の件数を取得
		BSWSDao bSWSDao = new BSWSDao();
		ArrayList<TenpoModel> tenpoList = bSWSDao.getTenpoJoho(con, null, bSWSSession.getStrGroupCod(), strSansyoTenpoCod, null);
		int intGyogu = tenpoList.get(0).getIntGyoSu();
		for(int i = raitenJohoBeanList.size(); raitenJohoBeanList.size() < intGyogu; i++){
			RaitenJohoBean raitenJohoBean = new RaitenJohoBean();
			raitenJohoBean.setJugyoinList(kvJugyoinList);
			raitenJohoBean.setIntShinki(0);
			raitenJohoBean.setIntSairai(0);
			raitenJohoBean.setIntShimei(0);
			raitenJohoBean.setIntNyukyaku(0);
			raitenJohoBean.setIntHontaiKingaku(0);
			raitenJohoBean.setIntSyohizei(0);
			raitenJohoBean.setIntUriageGokei(0);
			raitenJohoBean.setIntTanka(0);
			raitenJohoBean.setIntHosyuGokei(0);

			List<MasterBean> raitenYoinList = new ArrayList<MasterBean>();
			//ヘッダー順にリスト作成
			for(MasterBean masterBean:raitenYoinHList){
				MasterBean mb = new MasterBean();
				mb.setIntSeq(masterBean.getIntSeq());
				mb.setIntValue(0);
				raitenYoinList.add(mb);
			}
			raitenJohoBean.setRaitenYoinList(raitenYoinList);
			List<MasterBean> uriageShubetsuList = new ArrayList<MasterBean>();
			//ヘッダー順にリスト作成
			for(MasterBean masterBean:uriageShubetsuHList){
				MasterBean mb = new MasterBean();
				mb.setIntSeq(masterBean.getIntSeq());
				mb.setIntValue(0);
				uriageShubetsuList.add(mb);
			}
			raitenJohoBean.setUriageShubetsuList(uriageShubetsuList);

			List<MasterBean> shiharaiHohoList = new ArrayList<MasterBean>();
			//ヘッダー順にリスト作成
			for(MasterBean masterBean:shiharaiHohoHList){
				MasterBean mb = new MasterBean();
				mb.setIntSeq(masterBean.getIntSeq());
				mb.setHontaiKeijoFlg(masterBean.getHontaiKeijoFlg());
				mb.setIntValue(0);
				shiharaiHohoList.add(mb);
			}
			raitenJohoBean.setShiharaiHohoList(shiharaiHohoList);

			List<MasterBean> hosyuShubetsuList = new ArrayList<MasterBean>();
			//ヘッダー順にリスト作成
			for(MasterBean masterBean:hosyuShubetsuHList){
				MasterBean mb = new MasterBean();
				mb.setIntSeq(masterBean.getIntSeq());
				mb.setStrKeisanMotoCod(masterBean.getStrKeisanMotoCod());
				mb.setBdWariai(masterBean.getBdWariai());
				mb.setIntValue(0);
				hosyuShubetsuList.add(mb);
			}
			raitenJohoBean.setHosyuShubetsuList(hosyuShubetsuList);
			raitenJohoBeanList.add(raitenJohoBean);
		}

		return raitenJohoBeanList;
	}

	public RaitenJohoBean getGokeiRaitenJohoBean(List<RaitenJohoBean> raitenJohoBeanList){

		Integer intShinki = 0;
		Integer intSairai = 0;
		Integer intShimei = 0;
		Integer intNyukyaku = 0;
		Integer intHontaiKingaku = 0;
		Integer intSyohizei = 0;
		Integer intUriageGokei = 0;
		Integer intTanka = 0;
		Integer intHosyuGokei = 0;

		List<MasterBean> raitenYoinListGokei = new ArrayList<MasterBean>();
		List<MasterBean> uriageShubetsuListGokei = new ArrayList<MasterBean>();
		List<MasterBean> shiharaiHohoListGokei = new ArrayList<MasterBean>();
		List<MasterBean> hosyuShubetsuListGokei = new ArrayList<MasterBean>();

		boolean firstFlg = true;
		for( RaitenJohoBean raitenJohoBean:raitenJohoBeanList){
			intShinki += raitenJohoBean.getIntShinki();
			intSairai += raitenJohoBean.getIntSairai();
			intShimei += raitenJohoBean.getIntShimei();
			intNyukyaku += raitenJohoBean.getIntNyukyaku();
			intHontaiKingaku += raitenJohoBean.getIntHontaiKingaku();
			intSyohizei += raitenJohoBean.getIntSyohizei();
			intUriageGokei += raitenJohoBean.getIntUriageGokei();
			intTanka += raitenJohoBean.getIntTanka();
			intHosyuGokei += raitenJohoBean.getIntHosyuGokei();

			List<MasterBean> tempRyList = raitenJohoBean.getRaitenYoinList();
			List<MasterBean> tempUsList = raitenJohoBean.getUriageShubetsuList();
			List<MasterBean> tempShList = raitenJohoBean.getShiharaiHohoList();
			List<MasterBean> tempHsList = raitenJohoBean.getHosyuShubetsuList();


			//mbを数分作成
			if(firstFlg){
				for(MasterBean tmpKv:tempRyList){
					MasterBean mb = new MasterBean();
					mb.setIntSeq(tmpKv.getIntSeq());
					raitenYoinListGokei.add(mb);
				}
				for(MasterBean tmpKv:tempUsList){
					MasterBean mb = new MasterBean();
					mb.setIntSeq(tmpKv.getIntSeq());
					uriageShubetsuListGokei.add(mb);
				}
				for(MasterBean tmpKv:tempShList){
					MasterBean mb = new MasterBean();
					mb.setIntSeq(tmpKv.getIntSeq());
					shiharaiHohoListGokei.add(mb);
				}
				for(MasterBean tmpKv:tempHsList){
					MasterBean mb = new MasterBean();
					mb.setIntSeq(tmpKv.getIntSeq());
					hosyuShubetsuListGokei.add(mb);
				}
				firstFlg = false;
			}

			for(MasterBean tmpMb:tempRyList){
				for(MasterBean gokeiMb:raitenYoinListGokei){
					//keyが一致した時のみ加算
					if(tmpMb.getIntSeq() == gokeiMb.getIntSeq()){
						int gokeiSu = gokeiMb.getIntValue();
						gokeiSu += tmpMb.getIntValue();
						gokeiMb.setIntValue(gokeiSu);
					}
				}
			}
			for(MasterBean tmpMb:tempUsList){
				for(MasterBean gokeiMb:uriageShubetsuListGokei){
					//keyが一致した時のみ加算
					if(tmpMb.getIntSeq() == gokeiMb.getIntSeq()){
						int gokeiSu = gokeiMb.getIntValue();
						gokeiSu += tmpMb.getIntValue();
						gokeiMb.setIntValue(gokeiSu);
					}
				}
			}
			for(MasterBean tmpMb:tempShList){
				for(MasterBean gokeiMb:shiharaiHohoListGokei){
					//keyが一致した時のみ加算
					if(tmpMb.getIntSeq() == gokeiMb.getIntSeq()){
						int gokeiSu = gokeiMb.getIntValue();
						gokeiSu += tmpMb.getIntValue();
						gokeiMb.setIntValue(gokeiSu);
					}
				}
			}
			for(MasterBean tmpMb:tempHsList){
				for(MasterBean gokeiMb:hosyuShubetsuListGokei){
					//keyが一致した時のみ加算
					if(tmpMb.getIntSeq() == gokeiMb.getIntSeq()){
						int gokeiSu = gokeiMb.getIntValue();
						gokeiSu += tmpMb.getIntValue();
						gokeiMb.setIntValue(gokeiSu);
					}
				}
			}
		}

		RaitenJohoBean tmpBean = new RaitenJohoBean();
		tmpBean.setIntShinki(intShinki);
		tmpBean.setIntSairai(intSairai);
		tmpBean.setIntShimei(intShimei);
		tmpBean.setIntNyukyaku(intNyukyaku);
		tmpBean.setIntHontaiKingaku(intHontaiKingaku);
		tmpBean.setIntSyohizei(intSyohizei);
		tmpBean.setIntUriageGokei(intUriageGokei);
		tmpBean.setIntTanka(intTanka);
		tmpBean.setIntHosyuGokei(intHosyuGokei);

		tmpBean.setRaitenYoinList(raitenYoinListGokei);
		tmpBean.setUriageShubetsuList(uriageShubetsuListGokei);
		tmpBean.setShiharaiHohoList(shiharaiHohoListGokei);
		tmpBean.setHosyuShubetsuList(hosyuShubetsuListGokei);

		return tmpBean;
	}

	public NikkeiJohoBean getNikkeiJoho(
			Connection con, BSWSSession bSWSSession,
			List<MasterBean> uriageShubetsuHList,
			List<MasterBean> shiharaiHohoHList,
			List<MasterBean> genkinShutsunoHList,
			String strSansyoTenpoCod,
			String strSansyoYmd) throws Exception{

		UriageDao uriageDao = UriageDao.getInstance();



		// 売上情報取得
		List<UriageModel> uriageModelList = uriageDao.getUriageNikkeiJoho(con,
				bSWSSession.getStrGroupCod(), strSansyoTenpoCod, null,
				Integer.parseInt(strSansyoYmd));
		// 売上売上種別情報取得
		List<UriageSyosaiModel> uriageUriageShubetsuList = uriageDao.getUriageNikkeiSyosaiJoho(con,
				bSWSSession.getStrGroupCod(), strSansyoTenpoCod, null,
				BSWSConstants.KBN_URIAGE_SHUBETSU, null, Integer.parseInt(strSansyoYmd));
		// 売上支払方法情報取得
		List<UriageSyosaiModel> uriageShiharaiHohoList = uriageDao.getUriageNikkeiSyosaiJoho(con,
				bSWSSession.getStrGroupCod(), strSansyoTenpoCod, null,
				BSWSConstants.KBN_SHIHARAI_HOHO, null, Integer.parseInt(strSansyoYmd));
		// 現金出納情報取得
		List<UriageSyosaiModel> uriageGenkinShutsunoList = uriageDao.getUriageNikkeiSyosaiJoho(con,
				bSWSSession.getStrGroupCod(), strSansyoTenpoCod, null,
				BSWSConstants.KBN_GENKIN_SHUTSUNO, null, Integer.parseInt(strSansyoYmd));


//		// 売上情報取得
//		List<UriageModel> uriageModelList = uriageDao.getUriageNikkeiJoho(con,
//				bSWSSession.getStrGroupCod(), strSansyoTenpoCod,
//				null,
//				Integer.parseInt(strSansyoYmd));
//		// 売上売上種別情報取得
//		List<UriageSyosaiModel> uriageUriageShubetsuList = uriageDao.getUriageNikkeiUriageShubetsuJoho(con,
//				bSWSSession.getStrGroupCod(), strSansyoTenpoCod,
//				null,
//				null,
//				Integer.parseInt(strSansyoYmd));
//		// 売上支払方法情報取得
//		List<UriageSyosaiModel> uriageShiharaiHohoList = uriageDao.getUriageNikkeiShiharaiHohoJoho(con,
//				bSWSSession.getStrGroupCod(), strSansyoTenpoCod,
//				null,
//				null,
//				Integer.parseInt(strSansyoYmd));
//		// 現金出納情報取得
//		List<UriageSyosaiModel> uriageGenkinShutsunoList = uriageDao.getUriageNikkeiGenkinShutsunoJoho(con,
//				bSWSSession.getStrGroupCod(), strSansyoTenpoCod,
//				null,
//				null,
//				Integer.parseInt(strSansyoYmd));

		NikkeiJohoBean nikkeiJohoBean = new NikkeiJohoBean();
		//売上が取得できない場合、１行のみのリストを作成。
		if( uriageModelList.size() == 0 || uriageModelList == null ){
			uriageModelList.add(new UriageModel());
		}
		for(UriageModel uriageModel : uriageModelList){

			nikkeiJohoBean.setIntShinki(BSWSUtils.getZeroInteger(uriageModel.getIntShinkiSu()));
			nikkeiJohoBean.setIntShinki(BSWSUtils.getZeroInteger(uriageModel.getIntShinkiSu()));

			nikkeiJohoBean.setIntShinki(BSWSUtils.getZeroInteger(uriageModel.getIntShinkiSu()));
			nikkeiJohoBean.setIntSairai(BSWSUtils.getZeroInteger(uriageModel.getIntSairaiSu()));
			nikkeiJohoBean.setIntShimei(BSWSUtils.getZeroInteger(uriageModel.getIntShimeiSu()));
			nikkeiJohoBean.setIntNyukyaku(BSWSUtils.getZeroInteger(uriageModel.getIntNyukyakuSu()));
			nikkeiJohoBean.setIntHontaiKingaku(BSWSUtils.getZeroInteger(uriageModel.getIntHontaiKin()));
			nikkeiJohoBean.setIntSyohizei(BSWSUtils.getZeroInteger(uriageModel.getIntSyohizeiKin()));
			nikkeiJohoBean.setIntUriageGokei(BSWSUtils.getZeroInteger(uriageModel.getIntUriageGokeiKin()));
			nikkeiJohoBean.setIntTanka(BSWSUtils.getZeroInteger(uriageModel.getIntTankaKin()));
			nikkeiJohoBean.setIntHosyuGokei(BSWSUtils.getZeroInteger(uriageModel.getIntHosyuGokeiKin()));

			List<MasterBean> uriageShubetsuList = new ArrayList<MasterBean>();
			//ヘッダー順にリスト作成
			for(MasterBean masterBean:uriageShubetsuHList){
				MasterBean mb = new MasterBean();
				mb.setStrCod(masterBean.getStrCod());
				mb.setStrValue(masterBean.getStrValue());
				mb.setIntValue(0);
				//数字のリスト化
				for(UriageSyosaiModel uriageSyosaiModel:uriageUriageShubetsuList){
					//一致するものだけADD
					if(uriageModel.getIntUriageYmd().equals(uriageSyosaiModel.getIntUriageYmd()) //ここまで１行の単位
							&& masterBean.getIntSeq() == uriageSyosaiModel.getIntSeq() //列の単位
					){
						mb.setIntValue(uriageSyosaiModel.getIntAtai());
					}
				}
				uriageShubetsuList.add(mb);
			}
			nikkeiJohoBean.setUriageShubetsuList(uriageShubetsuList);

			List<MasterBean> shiharaiHohoList = new ArrayList<MasterBean>();
			//ヘッダー順にリスト作成
			for(MasterBean masterBean:shiharaiHohoHList){
				if(BSWSConstants.C_HONTAI_KEIJO.equals(masterBean.getHontaiKeijoFlg())){
					MasterBean mb = new MasterBean();
					mb.setStrCod(masterBean.getStrCod());
					mb.setStrValue(masterBean.getStrValue());
					mb.setHontaiKeijoFlg(masterBean.getHontaiKeijoFlg());
					mb.setIntValue(0);
					//数字のリスト化
					for(UriageSyosaiModel uriageSyosaiModel:uriageShiharaiHohoList){
						//一致するものだけADD
						if(uriageModel.getIntUriageYmd().equals(uriageSyosaiModel.getIntUriageYmd()) //ここまで１行の単位
								&& masterBean.getIntSeq() == uriageSyosaiModel.getIntSeq() //列の単位
						){
							mb.setIntValue(uriageSyosaiModel.getIntAtai());
						}
					}
					shiharaiHohoList.add(mb);
				}
			}
			nikkeiJohoBean.setUriageShiharaiHohoList(shiharaiHohoList);

			List<MasterBean> nikkeiShiharaiHohoList = new ArrayList<MasterBean>();
			//ヘッダー順にリスト作成
			for(MasterBean masterBean:shiharaiHohoHList){
				MasterBean mb = new MasterBean();
				mb.setStrCod(masterBean.getStrCod());
				mb.setStrValue(masterBean.getStrValue());
				mb.setHontaiKeijoFlg(masterBean.getHontaiKeijoFlg());
				mb.setIntValue(0);
				//数字のリスト化
				for(UriageSyosaiModel uriageSyosaiModel:uriageShiharaiHohoList){
					//一致するものだけADD
					if(uriageModel.getIntUriageYmd().equals(uriageSyosaiModel.getIntUriageYmd()) //ここまで１行の単位
							&& masterBean.getIntSeq() == uriageSyosaiModel.getIntSeq() //列の単位
					){
						mb.setIntValue(uriageSyosaiModel.getIntAtai());
					}
				}
				nikkeiShiharaiHohoList.add(mb);
			}

			nikkeiJohoBean.setNikkeiShiharaiHohoList(nikkeiShiharaiHohoList);

			List<MasterBean> genkinShutsunoList = new ArrayList<MasterBean>();
			//ヘッダー順にリスト作成
			for(MasterBean masterBean:genkinShutsunoHList){
				MasterBean mb = new MasterBean();
				mb.setStrCod(masterBean.getStrCod());
				mb.setStrValue(masterBean.getStrValue());
				mb.setIntValue(0);
				//数字のリスト化
				for(UriageSyosaiModel uriageSyosaiModel:uriageGenkinShutsunoList){
					//一致するものだけADD
					if(uriageModel.getIntUriageYmd().equals(uriageSyosaiModel.getIntUriageYmd()) //ここまで１行の単位
							&& masterBean.getIntSeq() == uriageSyosaiModel.getIntSeq() //列の単位
					){
						mb.setIntValue(uriageSyosaiModel.getIntAtai());
					}
				}
				genkinShutsunoList.add(mb);
			}

			MasterBean mbGokei = new MasterBean();
			int intMbGokei = 0;
			for(MasterBean mb:genkinShutsunoList){
				//一致するものだけADD
				intMbGokei += mb.getIntValue();
			}
			mbGokei.setIntValue(intMbGokei);
			nikkeiJohoBean.setIntGenkinShutsunoGokei(intMbGokei);
			nikkeiJohoBean.setGenkinShutsunoList(genkinShutsunoList);

			int tmpNUG = nikkeiJohoBean.getIntUriageGokei()
			- nikkeiJohoBean.getIntSyohizei()
			- nikkeiJohoBean.getIntHosyuGokei()
			- nikkeiJohoBean.getIntGenkinShutsunoGokei();
			nikkeiJohoBean.setIntNikkeiUriageGokei(tmpNUG);
			int tmpNr = 0;
			List<MasterBean> tmpNJB = nikkeiJohoBean.getNikkeiShiharaiHohoList();
			for(MasterBean tmpMb: tmpNJB){
				tmpNr = tmpNr + tmpMb.getIntValue();
			}
			nikkeiJohoBean.setIntNikkeiRieki(nikkeiJohoBean.getIntNikkeiUriageGokei() - tmpNr);
			nikkeiJohoBean.setIntNyukyakuTanka(nikkeiJohoBean.getIntTanka());
		}

		return nikkeiJohoBean;
	}

	public List<GekkeiJohoBean> getGekkeiJoho(
			Connection con, BSWSSession bSWSSession,
			List<MasterBean> raitenYoinHList,
			List<MasterBean> uriageShubetsuHList,
			List<MasterBean> shiharaiHohoHList,
			List<MasterBean> hosyuShubetsuHList,
			String strSansyoTenpoCod, Integer intSansyoJugyoinSeq,
			String strSansyoYmdFrom, String strSansyoYmdTo) throws Exception{

		UriageDao uriageDao = UriageDao.getInstance();

		// 売上情報取得
		List<UriageModel> uriageModelList = uriageDao.getUriageGekkeiJoho(con,
				bSWSSession.getStrGroupCod(), strSansyoTenpoCod, intSansyoJugyoinSeq,
				Integer.parseInt(strSansyoYmdFrom), Integer.parseInt(strSansyoYmdTo));
		// 売上来店要因情報取得
		List<UriageSyosaiModel> uriageRaitenYoinList = uriageDao.getUriageGekkeiSyosaiJoho(con,
				bSWSSession.getStrGroupCod(), strSansyoTenpoCod, intSansyoJugyoinSeq,
				BSWSConstants.KBN_RAITEN_YOIN, null,
				Integer.parseInt(strSansyoYmdFrom), Integer.parseInt(strSansyoYmdTo));
//		// 売上売上種別情報取得
//		List<UriageSyosaiModel> uriageUriageShubetsuList = uriageDao.getUriageGekkeiSyosaiJoho(con,
//				bSWSSession.getStrGroupCod(), strSansyoTenpoCod, intSansyoJugyoinSeq,
//				BSWSConstants.KBN_URIAGE_SHUBETSU, null,
//				Integer.parseInt(strSansyoYmdFrom), Integer.parseInt(strSansyoYmdTo));
		// 売上支払方法情報取得
		List<UriageSyosaiModel> uriageShiharaiHohoList = uriageDao.getUriageGekkeiSyosaiJoho(con,
				bSWSSession.getStrGroupCod(), strSansyoTenpoCod, intSansyoJugyoinSeq,
				BSWSConstants.KBN_SHIHARAI_HOHO, null,
				Integer.parseInt(strSansyoYmdFrom), Integer.parseInt(strSansyoYmdTo));
//		// 売上報酬種別情報取得
//		List<UriageSyosaiModel> uriageHosyuShubetsuList = uriageDao.getUriageGekkeiSyosaiJoho(con,
//				bSWSSession.getStrGroupCod(), strSansyoTenpoCod, intSansyoJugyoinSeq,
//				BSWSConstants.KBN_HOSYU_SHUBETSU, null,
//				Integer.parseInt(strSansyoYmdFrom), Integer.parseInt(strSansyoYmdTo));

		List<GekkeiJohoBean> gekkeiJohoBeanList = new ArrayList<GekkeiJohoBean>();
		for(UriageModel uriageModel : uriageModelList){
			GekkeiJohoBean gekkeiJohoBean = new GekkeiJohoBean();
			gekkeiJohoBean.setIntUriageYmd(uriageModel.getIntUriageYmd());
			gekkeiJohoBean.setIntShinki(uriageModel.getIntShinkiSu());
			gekkeiJohoBean.setIntSairai(uriageModel.getIntSairaiSu());
			gekkeiJohoBean.setIntShimei(uriageModel.getIntShimeiSu());
			gekkeiJohoBean.setIntNyukyaku(uriageModel.getIntNyukyakuSu());
			gekkeiJohoBean.setIntHontaiKingaku(uriageModel.getIntHontaiKin());
			gekkeiJohoBean.setIntSyohizei(uriageModel.getIntSyohizeiKin());
			gekkeiJohoBean.setIntUriageGokei(uriageModel.getIntUriageGokeiKin());
			gekkeiJohoBean.setIntTanka(uriageModel.getIntTankaKin());
			gekkeiJohoBean.setIntHosyuGokei(uriageModel.getIntHosyuGokeiKin());

			List<KeyValueSyukeiBean> raitenYoinList = new ArrayList<KeyValueSyukeiBean>();
			//ヘッダー順にリスト作成
			for(MasterBean masterBean:raitenYoinHList){
				KeyValueSyukeiBean kv = new KeyValueSyukeiBean();
				kv.setKey(String.valueOf(masterBean.getIntSeq()));
				kv.setValue(0);
				//数字のリスト化
				for(UriageSyosaiModel uriageSyosaiModel:uriageRaitenYoinList){
					//一致するものだけADD
					if(uriageModel.getIntUriageYmd().equals(uriageSyosaiModel.getIntUriageYmd()) //ここまで１行の単位
							&& masterBean.getIntSeq() == uriageSyosaiModel.getIntSeq() //列の単位
					){
						kv.setValue(uriageSyosaiModel.getIntAtai());
					}
				}
				raitenYoinList.add(kv);
			}
			gekkeiJohoBean.setRaitenYoinList(raitenYoinList);

//			List<KeyValueSyukeiBean> uriageShubetsuList = new ArrayList<KeyValueSyukeiBean>();
//			//ヘッダー順にリスト作成
//			for(MasterBean masterBean:uriageShubetsuHList){
//				KeyValueSyukeiBean kv = new KeyValueSyukeiBean();
//				kv.setKey(String.valueOf(masterBean.getIntSeq()));
//				kv.setValue(0);
//				//数字のリスト化
//				for(UriageSyosaiModel uriageSyosaiModel:uriageUriageShubetsuList){
//					//一致するものだけADD
//					if(uriageModel.getIntUriageYmd().equals(uriageSyosaiModel.getIntUriageYmd()) //ここまで１行の単位
//							&& masterBean.getIntSeq() == uriageSyosaiModel.getIntSeq() //列の単位
//					){
//						kv.setValue(uriageSyosaiModel.getIntAtai());
//					}
//				}
//				uriageShubetsuList.add(kv);
//			}
//			gekkeiJohoBean.setUriageShubetsuList(uriageShubetsuList);
//
			List<KeyValueSyukeiBean> shiharaiHohoList = new ArrayList<KeyValueSyukeiBean>();
			//ヘッダー順にリスト作成
			for(MasterBean masterBean:shiharaiHohoHList){
				KeyValueSyukeiBean kv = new KeyValueSyukeiBean();
				kv.setKey(String.valueOf(masterBean.getIntSeq()));
				kv.setValue(0);
				//数字のリスト化
				for(UriageSyosaiModel uriageSyosaiModel:uriageShiharaiHohoList){
					//一致するものだけADD
					if(uriageModel.getIntUriageYmd().equals(uriageSyosaiModel.getIntUriageYmd()) //ここまで１行の単位
							&& masterBean.getIntSeq() == uriageSyosaiModel.getIntSeq() //列の単位
					){
						kv.setValue(uriageSyosaiModel.getIntAtai());
					}
				}
				shiharaiHohoList.add(kv);
			}
			gekkeiJohoBean.setShiharaiHohoList(shiharaiHohoList);
//
//			List<KeyValueSyukeiBean> hosyuShubetsuList = new ArrayList<KeyValueSyukeiBean>();
//			//ヘッダー順にリスト作成
//			for(MasterBean masterBean:hosyuShubetsuHList){
//				KeyValueSyukeiBean kv = new KeyValueSyukeiBean();
//				kv.setKey(String.valueOf(masterBean.getIntSeq()));
//				kv.setValue(0);
//				//数字のリスト化
//				for(UriageSyosaiModel uriageSyosaiModel:uriageHosyuShubetsuList){
//					//一致するものだけADD
//					if(uriageModel.getIntUriageYmd().equals(uriageSyosaiModel.getIntUriageYmd()) //ここまで１行の単位
//							&& masterBean.getIntSeq() == uriageSyosaiModel.getIntSeq() //列の単位
//					){
//						kv.setValue(uriageSyosaiModel.getIntAtai());
//					}
//				}
//				hosyuShubetsuList.add(kv);
//			}
//			gekkeiJohoBean.setHosyuShubetsuList(hosyuShubetsuList);

			gekkeiJohoBeanList.add(gekkeiJohoBean);
		}

		return gekkeiJohoBeanList;
	}

	public GekkeiJohoBean getGokeiGekkeiBean(List<GekkeiJohoBean> gekkeiJohoBeanList, String strSansyoYmdFrom, String strSansyoYmdTo){

		Integer intShinki = 0;
		Integer intSairai = 0;
		Integer intShimei = 0;
		Integer intNyukyaku = 0;
		Integer intHontaiKingaku = 0;
		Integer intSyohizei = 0;
		Integer intUriageGokei = 0;
		Integer intTanka = 0;
		Integer intHosyuGokei = 0;

		List<KeyValueSyukeiBean> raitenYoinListGokei = new ArrayList<KeyValueSyukeiBean>();
//		List<KeyValueSyukeiBean> uriageShubetsuListGokei = new ArrayList<KeyValueSyukeiBean>();
		List<KeyValueSyukeiBean> shiharaiHohoListGokei = new ArrayList<KeyValueSyukeiBean>();
//		List<KeyValueSyukeiBean> hosyuShubetsuListGokei = new ArrayList<KeyValueSyukeiBean>();

		boolean firstFlg = true;
		for( GekkeiJohoBean gekkeiJohoBean:gekkeiJohoBeanList){
			intShinki += gekkeiJohoBean.getIntShinki();
			intSairai += gekkeiJohoBean.getIntSairai();
			intShimei += gekkeiJohoBean.getIntShimei();
			intNyukyaku += gekkeiJohoBean.getIntNyukyaku();
			intHontaiKingaku += gekkeiJohoBean.getIntHontaiKingaku();
			intSyohizei += gekkeiJohoBean.getIntSyohizei();
			intUriageGokei += gekkeiJohoBean.getIntUriageGokei();
			intTanka += gekkeiJohoBean.getIntTanka();
			intHosyuGokei += gekkeiJohoBean.getIntHosyuGokei();

			List<KeyValueSyukeiBean> tempRyList = gekkeiJohoBean.getRaitenYoinList();
//			List<KeyValueSyukeiBean> tempUsList = gekkeiJohoBean.getUriageShubetsuList();
			List<KeyValueSyukeiBean> tempShList = gekkeiJohoBean.getShiharaiHohoList();
//			List<KeyValueSyukeiBean> tempHsList = gekkeiJohoBean.getHosyuShubetsuList();


			//kvを数分作成
			if(firstFlg){
				for(KeyValueSyukeiBean tmpKv:tempRyList){
					KeyValueSyukeiBean kv = new KeyValueSyukeiBean();
					kv.setKey(tmpKv.getKey());
					raitenYoinListGokei.add(kv);
				}
//				for(KeyValueSyukeiBean tmpKv:tempUsList){
//					KeyValueSyukeiBean kv = new KeyValueSyukeiBean();
//					kv.setKey(tmpKv.getKey());
//					uriageShubetsuListGokei.add(kv);
//				}
				for(KeyValueSyukeiBean tmpKv:tempShList){
					KeyValueSyukeiBean kv = new KeyValueSyukeiBean();
					kv.setKey(tmpKv.getKey());
					shiharaiHohoListGokei.add(kv);
				}
//				for(KeyValueSyukeiBean tmpKv:tempHsList){
//					KeyValueSyukeiBean kv = new KeyValueSyukeiBean();
//					kv.setKey(tmpKv.getKey());
//					hosyuShubetsuListGokei.add(kv);
//				}
				firstFlg = false;
			}

			for(KeyValueSyukeiBean tmpKv:tempRyList){
				for(KeyValueSyukeiBean gokeiMb:raitenYoinListGokei){
					//keyが一致した時のみ加算
					if(tmpKv.getKey().equals(gokeiMb.getKey())){
						int gokeiSu = gokeiMb.getValue();
						gokeiSu += tmpKv.getValue();
						gokeiMb.setValue(gokeiSu);
					}
				}
			}
//			for(KeyValueSyukeiBean tmpKv:tempUsList){
//				for(KeyValueSyukeiBean gokeiMb:uriageShubetsuListGokei){
//					//keyが一致した時のみ加算
//					if(tmpKv.getKey().equals(gokeiMb.getKey())){
//						int gokeiSu = gokeiMb.getValue();
//						gokeiSu += tmpKv.getValue();
//						gokeiMb.setValue(gokeiSu);
//					}
//				}
//			}
			for(KeyValueSyukeiBean tmpKv:tempShList){
				for(KeyValueSyukeiBean gokeiMb:shiharaiHohoListGokei){
					//keyが一致した時のみ加算
					if(tmpKv.getKey().equals(gokeiMb.getKey())){
						int gokeiSu = gokeiMb.getValue();
						gokeiSu += tmpKv.getValue();
						gokeiMb.setValue(gokeiSu);
					}
				}
			}
//			for(KeyValueSyukeiBean tmpKv:tempHsList){
//				for(KeyValueSyukeiBean gokeiMb:hosyuShubetsuListGokei){
//					//keyが一致した時のみ加算
//					if(tmpKv.getKey().equals(gokeiMb.getKey())){
//						int gokeiSu = gokeiMb.getValue();
//						gokeiSu += tmpKv.getValue();
//						gokeiMb.setValue(gokeiSu);
//					}
//				}
//			}
		}

		GekkeiJohoBean tmpBean = new GekkeiJohoBean();
		tmpBean.setIntShinki(intShinki);
		tmpBean.setIntSairai(intSairai);
		tmpBean.setIntShimei(intShimei);
		tmpBean.setIntNyukyaku(intNyukyaku);
		tmpBean.setIntHontaiKingaku(intHontaiKingaku);
		tmpBean.setIntSyohizei(intSyohizei);
		tmpBean.setIntUriageGokei(intUriageGokei);
		tmpBean.setIntTanka(intTanka);
		tmpBean.setIntHosyuGokei(intHosyuGokei);

		tmpBean.setRaitenYoinList(raitenYoinListGokei);
//		tmpBean.setUriageShubetsuList(uriageShubetsuListGokei);
		tmpBean.setShiharaiHohoList(shiharaiHohoListGokei);
//		tmpBean.setHosyuShubetsuList(hosyuShubetsuListGokei);

		int systemYmd = Integer.parseInt(BSWSUtils.getSysDateYmd());
		//システム日付と１日の差
		tmpBean.setIntAveCnt(systemYmd - Integer.parseInt(strSansyoYmdFrom) - 1);
		//予測用のカウント
		tmpBean.setIntTsukiCnt(Integer.parseInt(strSansyoYmdTo) - Integer.parseInt(strSansyoYmdFrom) - 1);
		return tmpBean;
	}

	public List<NenkanJohoBean> getNenkanJoho(
			Connection con, BSWSSession bSWSSession,
			List<MasterBean> raitenYoinHList,
			List<MasterBean> uriageShubetsuHList,
			List<MasterBean> shiharaiHohoHList,
			List<MasterBean> hosyuShubetsuHList,
			String strSansyoTenpoCod, Integer intSansyoJugyoinSeq,
			String strSansyoY) throws Exception{

		UriageDao uriageDao = UriageDao.getInstance();

		List<NenkanJohoBean> nenkanJohoBeanList = new ArrayList<NenkanJohoBean>();

		//12ヶ月分取得
		for(int m = 1; m <= 12; m++){

			//年月取得
			String mm = BSWSUtils.hidariUme(String.valueOf(m),2,"0");
			String strSansyoYmdFrom = strSansyoY + mm + "01";
			Calendar cal = Calendar.getInstance();

			int iyy = Integer.parseInt(strSansyoY);
			int imm = Integer.parseInt(mm);
			cal.set(Calendar.YEAR, iyy);
			cal.set(Calendar.MONTH, imm - 1);
			int idd = cal.getActualMaximum(Calendar.DATE);
			String dd = BSWSUtils.hidariUme(String.valueOf(idd),2,"0");
			String strSansyoYmdTo = strSansyoY + mm + dd;

			// 売上情報取得
			List<UriageModel> uriageModelList = uriageDao.getUriageNenkanJoho(con,
					bSWSSession.getStrGroupCod(), strSansyoTenpoCod, intSansyoJugyoinSeq,
					Integer.parseInt(strSansyoYmdFrom), Integer.parseInt(strSansyoYmdTo));
			// 売上来店要因情報取得
			List<UriageSyosaiModel> uriageRaitenYoinList = uriageDao.getUriageNenkanSyosaiJoho(con,
					bSWSSession.getStrGroupCod(), strSansyoTenpoCod, intSansyoJugyoinSeq,
					BSWSConstants.KBN_RAITEN_YOIN, null,
					Integer.parseInt(strSansyoYmdFrom), Integer.parseInt(strSansyoYmdTo));
//			// 売上売上種別情報取得
//			List<UriageSyosaiModel> uriageUriageShubetsuList = uriageDao.getUriageNenkanSyosaiJoho(con,
//					bSWSSession.getStrGroupCod(), strSansyoTenpoCod, intSansyoJugyoinSeq,
//					BSWSConstants.KBN_URIAGE_SHUBETSU, null,
//					Integer.parseInt(strSansyoYmdFrom), Integer.parseInt(strSansyoYmdTo));
//			// 売上支払方法情報取得
//			List<UriageSyosaiModel> uriageShiharaiHohoList = uriageDao.getUriageNenkanSyosaiJoho(con,
//					bSWSSession.getStrGroupCod(), strSansyoTenpoCod, intSansyoJugyoinSeq,
//					BSWSConstants.KBN_SHIHARAI_HOHO, null,
//					Integer.parseInt(strSansyoYmdFrom), Integer.parseInt(strSansyoYmdTo));
//			// 売上報酬種別情報取得
//			List<UriageSyosaiModel> uriageHosyuShubetsuList = uriageDao.getUriageNenkanSyosaiJoho(con,
//					bSWSSession.getStrGroupCod(), strSansyoTenpoCod, intSansyoJugyoinSeq,
//					BSWSConstants.KBN_HOSYU_SHUBETSU, null,
//					Integer.parseInt(strSansyoYmdFrom), Integer.parseInt(strSansyoYmdTo));

			for(UriageModel uriageModel : uriageModelList){
				NenkanJohoBean nenkanJohoBean = new NenkanJohoBean();
				nenkanJohoBean.setIntUriageYm(uriageModel.getIntUriageYm());
				nenkanJohoBean.setIntShinki(uriageModel.getIntShinkiSu());
				nenkanJohoBean.setIntSairai(uriageModel.getIntSairaiSu());
				nenkanJohoBean.setIntShimei(uriageModel.getIntShimeiSu());
				nenkanJohoBean.setIntNyukyaku(uriageModel.getIntNyukyakuSu());
				nenkanJohoBean.setIntHontaiKingaku(uriageModel.getIntHontaiKin());
				nenkanJohoBean.setIntSyohizei(uriageModel.getIntSyohizeiKin());
				nenkanJohoBean.setIntUriageGokei(uriageModel.getIntUriageGokeiKin());
				nenkanJohoBean.setIntTanka(uriageModel.getIntTankaKin());
				nenkanJohoBean.setIntHosyuGokei(uriageModel.getIntHosyuGokeiKin());

				nenkanJohoBean.setIntShinkiZen(uriageModel.getIntShinkiSuZen());
				nenkanJohoBean.setIntSairaiZen(uriageModel.getIntSairaiSuZen());
				nenkanJohoBean.setIntShimeiZen(uriageModel.getIntShimeiSuZen());
				nenkanJohoBean.setIntNyukyakuZen(uriageModel.getIntNyukyakuSuZen());
				nenkanJohoBean.setIntHontaiKingakuZen(uriageModel.getIntHontaiKinZen());
				nenkanJohoBean.setIntSyohizeiZen(uriageModel.getIntSyohizeiKinZen());
				nenkanJohoBean.setIntUriageGokeiZen(uriageModel.getIntUriageGokeiKinZen());
				nenkanJohoBean.setIntTankaZen(uriageModel.getIntTankaKinZen());
				nenkanJohoBean.setIntHosyuGokeiZen(uriageModel.getIntHosyuGokeiKinZen());

				List<KeyValueSyukeiBean> raitenYoinList = new ArrayList<KeyValueSyukeiBean>();
				//ヘッダー順にリスト作成
				for(MasterBean masterBean:raitenYoinHList){
					KeyValueSyukeiBean kv = new KeyValueSyukeiBean();
					kv.setKey(String.valueOf(masterBean.getIntSeq()));
					kv.setValue(0);
					//数字のリスト化
					for(UriageSyosaiModel uriageSyosaiModel:uriageRaitenYoinList){
						//一致するものだけADD
						if(uriageModel.getIntUriageYm().equals(uriageSyosaiModel.getIntUriageYm()) //ここまで１行の単位
								&& masterBean.getIntSeq() == uriageSyosaiModel.getIntSeq() //列の単位
						){
							kv.setValue(uriageSyosaiModel.getIntAtai());
							kv.setValueZen(uriageSyosaiModel.getIntAtaiZen());
						}
					}
					raitenYoinList.add(kv);
				}
				nenkanJohoBean.setRaitenYoinList(raitenYoinList);

//				List<KeyValueSyukeiBean> uriageShubetsuList = new ArrayList<KeyValueSyukeiBean>();
//				//ヘッダー順にリスト作成
//				for(MasterBean masterBean:uriageShubetsuHList){
//					KeyValueSyukeiBean kv = new KeyValueSyukeiBean();
//					kv.setKey(String.valueOf(masterBean.getIntSeq()));
//					kv.setValue(0);
//					//数字のリスト化
//					for(UriageSyosaiModel uriageSyosaiModel:uriageUriageShubetsuList){
//						//一致するものだけADD
//						if(uriageModel.getIntUriageYmd().equals(uriageSyosaiModel.getIntUriageYmd()) //ここまで１行の単位
//								&& masterBean.getIntSeq() == uriageSyosaiModel.getIntSeq() //列の単位
//						){
//							kv.setValue(uriageSyosaiModel.getIntAtai());
//						}
//					}
//					uriageShubetsuList.add(kv);
//				}
//				nenkanJohoBean.setUriageShubetsuList(uriageShubetsuList);
	//
//				List<KeyValueSyukeiBean> shiharaiHohoList = new ArrayList<KeyValueSyukeiBean>();
//				//ヘッダー順にリスト作成
//				for(MasterBean masterBean:shiharaiHohoHList){
//					KeyValueSyukeiBean kv = new KeyValueSyukeiBean();
//					kv.setKey(String.valueOf(masterBean.getIntSeq()));
//					kv.setValue(0);
//					//数字のリスト化
//					for(UriageSyosaiModel uriageSyosaiModel:uriageShiharaiHohoList){
//						//一致するものだけADD
//						if(uriageModel.getIntUriageYm().equals(uriageSyosaiModel.getIntUriageYm()) //ここまで１行の単位
//								&& masterBean.getIntSeq() == uriageSyosaiModel.getIntSeq() //列の単位
//						){
//							kv.setValue(uriageSyosaiModel.getIntAtai());
//						}
//					}
//					shiharaiHohoList.add(kv);
//				}
//				nenkanJohoBean.setShiharaiHohoList(shiharaiHohoList);
	//
//				List<KeyValueSyukeiBean> hosyuShubetsuList = new ArrayList<KeyValueSyukeiBean>();
//				//ヘッダー順にリスト作成
//				for(MasterBean masterBean:hosyuShubetsuHList){
//					KeyValueSyukeiBean kv = new KeyValueSyukeiBean();
//					kv.setKey(String.valueOf(masterBean.getIntSeq()));
//					kv.setValue(0);
//					//数字のリスト化
//					for(UriageSyosaiModel uriageSyosaiModel:uriageHosyuShubetsuList){
//						//一致するものだけADD
//						if(uriageModel.getIntUriageYmd().equals(uriageSyosaiModel.getIntUriageYmd()) //ここまで１行の単位
//								&& masterBean.getIntSeq() == uriageSyosaiModel.getIntSeq() //列の単位
//						){
//							kv.setValue(uriageSyosaiModel.getIntAtai());
//						}
//					}
//					hosyuShubetsuList.add(kv);
//				}
//				nenkanJohoBean.setHosyuShubetsuList(hosyuShubetsuList);

				nenkanJohoBeanList.add(nenkanJohoBean);
			}
		}


		return nenkanJohoBeanList;
	}

	public NenkanJohoBean getGokeiNenkanBean(List<NenkanJohoBean> nenkanJohoBeanList, String strSansyoY){

		Integer intShinki = 0;
		Integer intSairai = 0;
		Integer intShimei = 0;
		Integer intNyukyaku = 0;
		Integer intHontaiKingaku = 0;
		Integer intSyohizei = 0;
		Integer intUriageGokei = 0;
		Integer intTanka = 0;
		Integer intHosyuGokei = 0;

		Integer intShinkiZen = 0;
		Integer intSairaiZen = 0;
		Integer intShimeiZen = 0;
		Integer intNyukyakuZen = 0;
		Integer intHontaiKingakuZen = 0;
		Integer intSyohizeiZen = 0;
		Integer intUriageGokeiZen = 0;
		Integer intTankaZen = 0;
		Integer intHosyuGokeiZen = 0;

		List<KeyValueSyukeiBean> raitenYoinListGokei = new ArrayList<KeyValueSyukeiBean>();
//		List<KeyValueSyukeiBean> uriageShubetsuListGokei = new ArrayList<KeyValueSyukeiBean>();
//		List<KeyValueSyukeiBean> shiharaiHohoListGokei = new ArrayList<KeyValueSyukeiBean>();
//		List<KeyValueSyukeiBean> hosyuShubetsuListGokei = new ArrayList<KeyValueSyukeiBean>();

		boolean firstFlg = true;
		for( NenkanJohoBean nenkanJohoBean:nenkanJohoBeanList){
			intShinki += nenkanJohoBean.getIntShinki();
			intSairai += nenkanJohoBean.getIntSairai();
			intShimei += nenkanJohoBean.getIntShimei();
			intNyukyaku += nenkanJohoBean.getIntNyukyaku();
			intHontaiKingaku += nenkanJohoBean.getIntHontaiKingaku();
			intSyohizei += nenkanJohoBean.getIntSyohizei();
			intUriageGokei += nenkanJohoBean.getIntUriageGokei();
			intTanka += nenkanJohoBean.getIntTanka();
			intHosyuGokei += nenkanJohoBean.getIntHosyuGokei();

			intShinkiZen += nenkanJohoBean.getIntShinkiZen();
			intSairaiZen += nenkanJohoBean.getIntSairaiZen();
			intShimeiZen += nenkanJohoBean.getIntShimeiZen();
			intNyukyakuZen += nenkanJohoBean.getIntNyukyakuZen();
			intHontaiKingakuZen += nenkanJohoBean.getIntHontaiKingakuZen();
			intSyohizeiZen += nenkanJohoBean.getIntSyohizeiZen();
			intUriageGokeiZen += nenkanJohoBean.getIntUriageGokeiZen();
			intTankaZen += nenkanJohoBean.getIntTankaZen();
			intHosyuGokeiZen += nenkanJohoBean.getIntHosyuGokeiZen();

			List<KeyValueSyukeiBean> tempRyList = nenkanJohoBean.getRaitenYoinList();
//			List<KeyValueSyukeiBean> tempUsList = nenkanJohoBean.getUriageShubetsuList();
//			List<KeyValueSyukeiBean> tempShList = nenkanJohoBean.getShiharaiHohoList();
//			List<KeyValueSyukeiBean> tempHsList = nenkanJohoBean.getHosyuShubetsuList();


			//kvを数分作成
			if(firstFlg){
				for(KeyValueSyukeiBean tmpKv:tempRyList){
					KeyValueSyukeiBean kv = new KeyValueSyukeiBean();
					kv.setKey(tmpKv.getKey());
					raitenYoinListGokei.add(kv);
				}
//				for(KeyValueSyukeiBean tmpKv:tempUsList){
//					KeyValueSyukeiBean kv = new KeyValueSyukeiBean();
//					kv.setKey(tmpKv.getKey());
//					uriageShubetsuListGokei.add(kv);
//				}
//				for(KeyValueSyukeiBean tmpKv:tempShList){
//					KeyValueSyukeiBean kv = new KeyValueSyukeiBean();
//					kv.setKey(tmpKv.getKey());
//					shiharaiHohoListGokei.add(kv);
//				}
//				for(KeyValueSyukeiBean tmpKv:tempHsList){
//					KeyValueSyukeiBean kv = new KeyValueSyukeiBean();
//					kv.setKey(tmpKv.getKey());
//					hosyuShubetsuListGokei.add(kv);
//				}
				firstFlg = false;
			}

			for(KeyValueSyukeiBean tmpKv:tempRyList){
				for(KeyValueSyukeiBean gokeiMb:raitenYoinListGokei){
					//keyが一致した時のみ加算
					if(tmpKv.getKey().equals(gokeiMb.getKey())){
						int gokeiSu = gokeiMb.getValue();
						int gokeiSuZen = gokeiMb.getValueZen();
						gokeiSu += tmpKv.getValue();
						gokeiSuZen += tmpKv.getValueZen();
						gokeiMb.setValue(gokeiSu);
						gokeiMb.setValueZen(gokeiSuZen);
					}
				}
			}
//			for(KeyValueSyukeiBean tmpKv:tempUsList){
//				for(KeyValueSyukeiBean gokeiMb:uriageShubetsuListGokei){
//					//keyが一致した時のみ加算
//					if(tmpKv.getKey().equals(gokeiMb.getKey())){
//						int gokeiSu = gokeiMb.getValue();
//						gokeiSu += tmpKv.getValue();
//						gokeiMb.setValue(gokeiSu);
//					}
//				}
//			}
//			for(KeyValueSyukeiBean tmpKv:tempShList){
//				for(KeyValueSyukeiBean gokeiMb:shiharaiHohoListGokei){
//					//keyが一致した時のみ加算
//					if(tmpKv.getKey().equals(gokeiMb.getKey())){
//						int gokeiSu = gokeiMb.getValue();
//						gokeiSu += tmpKv.getValue();
//						gokeiMb.setValue(gokeiSu);
//					}
//				}
//			}
//			for(KeyValueSyukeiBean tmpKv:tempHsList){
//				for(KeyValueSyukeiBean gokeiMb:hosyuShubetsuListGokei){
//					//keyが一致した時のみ加算
//					if(tmpKv.getKey().equals(gokeiMb.getKey())){
//						int gokeiSu = gokeiMb.getValue();
//						gokeiSu += tmpKv.getValue();
//						gokeiMb.setValue(gokeiSu);
//					}
//				}
//			}
		}

		NenkanJohoBean tmpBean = new NenkanJohoBean();
		tmpBean.setIntShinki(intShinki);
		tmpBean.setIntSairai(intSairai);
		tmpBean.setIntShimei(intShimei);
		tmpBean.setIntNyukyaku(intNyukyaku);
		tmpBean.setIntHontaiKingaku(intHontaiKingaku);
		tmpBean.setIntSyohizei(intSyohizei);
		tmpBean.setIntUriageGokei(intUriageGokei);
		tmpBean.setIntTanka(intTanka);
		tmpBean.setIntHosyuGokei(intHosyuGokei);

		tmpBean.setIntShinkiZen(intShinkiZen);
		tmpBean.setIntSairaiZen(intSairaiZen);
		tmpBean.setIntShimeiZen(intShimeiZen);
		tmpBean.setIntNyukyakuZen(intNyukyakuZen);
		tmpBean.setIntHontaiKingakuZen(intHontaiKingakuZen);
		tmpBean.setIntSyohizeiZen(intSyohizeiZen);
		tmpBean.setIntUriageGokeiZen(intUriageGokeiZen);
		tmpBean.setIntTankaZen(intTankaZen);
		tmpBean.setIntHosyuGokeiZen(intHosyuGokeiZen);

		tmpBean.setRaitenYoinList(raitenYoinListGokei);
//		tmpBean.setUriageShubetsuList(uriageShubetsuListGokei);
//		tmpBean.setShiharaiHohoList(shiharaiHohoListGokei);
//		tmpBean.setHosyuShubetsuList(hosyuShubetsuListGokei);

		//過去年月の場合、12、当年の場合、1月からの年月
		String systemYm = BSWSUtils.getSysDateYm();
		String systemY = systemYm.substring(0,4);
		if(strSansyoY.equals(systemY) ){
			int imm = Integer.parseInt(systemYm.substring(4,6));
			//システム月と１月の差
			tmpBean.setIntAveCnt(imm);
		}else{
			//1年分
			tmpBean.setIntAveCnt(12);
		}

		//予測用のカウント(１年分)
		tmpBean.setIntTsukiCnt(12);
		return tmpBean;
	}

	public void updateRaitenJoho(
			Connection con, BSWSSession bSWSSession,
			List<RaitenJohoBean> raitenJohoList,
			String strSansyoTenpoCod, String strSansyoYmd) throws Exception{

		UriageDao uriageDao = UriageDao.getInstance();

		//売上情報削除登録
		int cnt = uriageDao.deleteUriageJoho(con, bSWSSession.getStrGroupCod(), strSansyoTenpoCod, BSWSUtils.getZeroInteger(strSansyoYmd));
		cnt = uriageDao.deleteUriageSyosai(con, bSWSSession.getStrGroupCod(), strSansyoTenpoCod, BSWSUtils.getZeroInteger(strSansyoYmd), null,  BSWSConstants.KBN_RAITEN_YOIN, null);
		cnt = uriageDao.deleteUriageSyosai(con, bSWSSession.getStrGroupCod(), strSansyoTenpoCod, BSWSUtils.getZeroInteger(strSansyoYmd), null, BSWSConstants.KBN_URIAGE_SHUBETSU, null);
		cnt = uriageDao.deleteUriageSyosai(con, bSWSSession.getStrGroupCod(), strSansyoTenpoCod, BSWSUtils.getZeroInteger(strSansyoYmd), null, BSWSConstants.KBN_SHIHARAI_HOHO, null);
		cnt = uriageDao.deleteUriageSyosai(con, bSWSSession.getStrGroupCod(), strSansyoTenpoCod, BSWSUtils.getZeroInteger(strSansyoYmd), null, BSWSConstants.KBN_HOSYU_SHUBETSU, null);
		for(RaitenJohoBean raitenJohoBean:raitenJohoList){
			if(raitenJohoBean.getIntTantoSeq() == null){
				continue;
			}
			int rowCnt = 0;
			//売上情報削除登録
			rowCnt = uriageDao.insertUriage(con, bSWSSession, strSansyoTenpoCod, BSWSUtils.getZeroInteger(strSansyoYmd), raitenJohoBean);
			List<MasterBean> raitenYoinList = raitenJohoBean.getRaitenYoinList();
			for(MasterBean masterBean :raitenYoinList){
				rowCnt = uriageDao.insertUriageSyosai(con, bSWSSession, strSansyoTenpoCod, strSansyoYmd, raitenJohoBean.getIntTantoSeq(), BSWSConstants.KBN_RAITEN_YOIN, masterBean.getIntSeq(), masterBean.getIntValue());
			}
			List<MasterBean> uriageShubetsuList = raitenJohoBean.getUriageShubetsuList();
			for(MasterBean masterBean :uriageShubetsuList){
				rowCnt = uriageDao.insertUriageSyosai(con, bSWSSession, strSansyoTenpoCod, strSansyoYmd, raitenJohoBean.getIntTantoSeq(), BSWSConstants.KBN_URIAGE_SHUBETSU, masterBean.getIntSeq(), masterBean.getIntValue());
			}
			List<MasterBean> shiharaiHohoList = raitenJohoBean.getShiharaiHohoList();
			for(MasterBean masterBean :shiharaiHohoList){
				rowCnt = uriageDao.insertUriageSyosai(con, bSWSSession, strSansyoTenpoCod, strSansyoYmd, raitenJohoBean.getIntTantoSeq(), BSWSConstants.KBN_SHIHARAI_HOHO, masterBean.getIntSeq(), masterBean.getIntValue());
			}
			List<MasterBean> hosyuShubetsuList = raitenJohoBean.getHosyuShubetsuList();
			for(MasterBean masterBean :hosyuShubetsuList){
				rowCnt = uriageDao.insertUriageSyosai(con, bSWSSession, strSansyoTenpoCod, strSansyoYmd, raitenJohoBean.getIntTantoSeq(), BSWSConstants.KBN_HOSYU_SHUBETSU, masterBean.getIntSeq(), masterBean.getIntValue());
			}
			if(rowCnt == 0){
				//登録なし
			}
		}
	}

	public void updateGenkinJoho(
			Connection con, BSWSSession bSWSSession,
			List<MasterBean> genkinJohoList,
			String strSansyoTenpoCod, String strSansyoYmd) throws Exception{

		UriageDao uriageDao = UriageDao.getInstance();

		//売上情報削除登録
		uriageDao.deleteGenkinShutsunoJoho(con, bSWSSession, strSansyoTenpoCod, Integer.parseInt(strSansyoYmd), null);
		int rowCnt = 0;
		for(MasterBean masterBean:genkinJohoList){
			//売上情報削除登録
			rowCnt = uriageDao.insertGenkinShutsuno(con, bSWSSession, strSansyoTenpoCod, strSansyoYmd, masterBean.getIntSeq(), masterBean.getIntValue());
			if(rowCnt == 0){
				//登録なし
			}
		}
	}

	public void updateNikkeiJoho(
			Connection con, BSWSSession bSWSSession,
			String strSansyoTenpoCod, String strSansyoYmd, String strShimeFlg) throws Exception{

		UriageDao uriageDao = UriageDao.getInstance();

		int rowCnt = 0;
		//売上情報削除登録
		rowCnt = uriageDao.deleteUriageNikkeiInfo(con, bSWSSession, strSansyoTenpoCod, Integer.parseInt(strSansyoYmd));
		//売上情報登録
		rowCnt = uriageDao.insertUriageNikkeiInfo(con, bSWSSession, strSansyoTenpoCod,  Integer.parseInt(strSansyoYmd), strShimeFlg);

		if(rowCnt == 0){
			//登録なし
		}
	}
}
